package com.qi.spzx.manager.mapper;

import com.qi.spzx.model.dto.product.CategoryBrandDto;
import com.qi.spzx.model.entity.product.Brand;
import com.qi.spzx.model.entity.product.CategoryBrand;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Description TODO
 * @Author dingchunlin
 * @Date 2024/2/23 16:58
 * @Version 1.0.0
 */
@Mapper
public interface CategoryBrandMapper {
    List<CategoryBrand> findByPage(CategoryBrandDto categoryBrandDto);

    @Insert("insert into category_brand values(null,#{brandId},#{categoryId},now(),now(),1)")
    void save(CategoryBrand categoryBrand);

    void updateById(CategoryBrand categoryBrand);

    @Update("update category_brand set update_time = now(),is_deleted = 0 where  id = #{id}")
    void deleteById(Long id);

    @Select("select count(0) from category_brand where brand_id = #{brandId} and category_id = #{categoryId} and is_deleted = 1;")
    Integer isAdd(CategoryBrand categoryBrand);

    @Select("select DISTINCT brand_id from category_brand where category_id = #{categoryId} and is_deleted = 1")
    List<Long> findBrandByCategoryId(Long categoryId);

}
